package avicit.bdp.dds.server.log;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

/**
 *  worker log filter
 */
public class WorkerLogFilter extends Filter<ILoggingEvent> {
    /**
     * level
     */
    Level level;

    /**
     * Accept or reject based on thread name
     * @param event event
     * @return FilterReply
     */
    @Override
    public FilterReply decide(ILoggingEvent event) {
        if (event.getThreadName().startsWith("Worker-")){
            return FilterReply.ACCEPT;
        }

        return FilterReply.DENY;
    }
    public void setLevel(String level) {
        this.level = Level.toLevel(level);
    }
}